#!/bin/bash

# 部署配置
DEPLOY_USER="pyapp"
DEPLOY_HOST="222.128.36.213"
DEPLOY_PORT="6022"
WWW_PATH="/home/pyapp/www/cardsys_test"

# SSH 命令基础，包含端口
SSH_CMD="ssh -p ${DEPLOY_PORT} -o StrictHostKeyChecking=no"
SCP_CMD="scp -P ${DEPLOY_PORT} -o StrictHostKeyChecking=no"

echo "开始部署卡系统测试平台前端..."

# 1. 准备前端构建（本地 macOS 环境）
echo "在本地构建前端代码..."
cd frontend
npm install
npm run build
cd ..

# 2. 创建远程目录
echo "创建远程目录..."
${SSH_CMD} ${DEPLOY_USER}@${DEPLOY_HOST} "mkdir -p ${WWW_PATH}/{assets,js,css}"

# 3. 上传前端构建文件
echo "上传前端构建文件..."
${SCP_CMD} -r frontend/dist/* ${DEPLOY_USER}@${DEPLOY_HOST}:${WWW_PATH}/

echo "前端部署完成！"
echo "请确保 Nginx 已正确配置并重启"

echo ""
echo "提示: 如需避免多次输入密码，请设置SSH密钥认证:"
echo "1. 在本地运行: ssh-keygen -t rsa"
echo "2. 将公钥复制到服务器: ssh-copy-id -p ${DEPLOY_PORT} ${DEPLOY_USER}@${DEPLOY_HOST}"
echo "3. 之后就可以免密码登录和部署了" 